package com.spzx.channel.controller;

import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.vo.CategoryVo;
import com.spzx.product.api.service.RemoteCategoryService;
import com.spzx.product.api.service.RemoteProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private RemoteCategoryService remoteCategoryService;

    @Autowired
    private RemoteProductSkuService remoteProductSkuService;

    @Operation(summary = "首页管理接口")
    @GetMapping
    public AjaxResult index(){
        R<List<CategoryVo>> oneCategory = remoteCategoryService.getOneCategory(0L, SecurityConstants.INNER);
        List<CategoryVo> categoryVoList = oneCategory.getData();
        //远程调用商品微服务获取畅销商品
        R<List<ProductSku>> topProductSku = remoteProductSkuService.getTopProductSku(SecurityConstants.INNER);
        //获取畅销商品集合
        List<ProductSku> topProductSkuList = topProductSku.getData();

        Map<String,Object> returnMap = new HashMap<>();
        returnMap.put("categoryList",categoryVoList);
        returnMap.put("productSkuList",topProductSkuList);
        return AjaxResult.success(returnMap);
    }
}
